package com.shuzi.MediaShare.download;

import java.io.File;
import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shuzi.MediaShare.R;
import com.shuzi.MediaShare.utils.StringUtils;

/**
 * 已下载电影本地视频
 * 
 * @author Administrator 下午4:57:20 2013
 */
public class LocalFileAdapter extends BaseAdapter
{

	private ArrayList<File> files;

	private Context context;

	public LocalFileAdapter(Context context, ArrayList<File> files)
	{
		this.context = context;
		this.files = files;
	}

	@Override
	public int getCount()
	{
		return files.size();
	}

	@Override
	public Object getItem(int position)
	{
		return files.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	public class ViewHolder
	{
		/** 电影名称 */
		public TextView movieName;

		/** 下载大小 */
		public TextView downloadSize;

		public ViewHolder(View baseView)
		{
			movieName = (TextView) baseView.findViewById(R.id.file_name);
			downloadSize = (TextView) baseView.findViewById(R.id.file_size);
		}

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder;
		if (convertView == null)
		{
			convertView = View.inflate(context, R.layout.had_download_item,
					null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}

		File file = files.get(position);
		holder.downloadSize.setText(StringUtils.bytes2kb(file.length()));
		holder.movieName.setText(file.getName());

		return convertView;
	}
}
